#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月17日

@author: Administrator
'''

from django.core.cache import cache

from message import settings

def make_user_message_cache_key(user_id, prefix=settings.USER_MESSAGE_CACHE_KEY):
    return prefix % {'user_id': user_id}

def get_user_message_cache(user_id):
    u'''
    function: 从缓存中获取用户未读消息数
    return: 例子{'total': 10, 'system': 5, 'normal': 2, 'letter': 3}
    '''
    cache_key = make_user_message_cache_key(user_id)
    return cache.get(cache_key)

def set_user_message_cache(user_id, val, timeout=settings.USER_MESSAGE_CACHE_TIMEOUT):
    cache_key = make_user_message_cache_key(user_id)
    return cache.set(cache_key, val, timeout=timeout)

def delete_user_message_cache(user_id):
    cache_key = make_user_message_cache_key(user_id)
    return cache.delete(cache_key)
